package com.hippoDocker.streamrabbitmqp.service.impl;

import com.hippoDocker.streamrabbitmqp.service.IMessageProvider;
import lombok.extern.log4j.Log4j2;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.context.annotation.EnableMBeanExport;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.messaging.MessageChannel;

import javax.annotation.Resource;
import java.util.UUID;

/**
 * @ClassName IMessageProviderImpl
 * @Description TODO 消息发送
 * @Author hippoDocker
 * @Date 2022/7/6 9:13
 **/
@EnableBinding(Source.class) //定义消息的推送管道
@Log4j2
public class IMessageProviderImpl implements IMessageProvider {
    @Resource
    private MessageChannel output; //消息发送管道

    @Override
    public String send() {
        String serial = UUID.randomUUID().toString();
        output.send(MessageBuilder.withPayload(serial).setHeader("partitionKey",serial).build());
        log.info("******serial:"+serial);
        return "******serial:"+serial;
    }
}
